package com.mcflies.commons;

import com.mcflies.ui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImitateUCMenuGridViewAdapter extends BaseAdapter {
	private Context context;
	private ImitateUCMenuItemData ucMenuItemData;
	private LayoutInflater inflater;

	public ImitateUCMenuGridViewAdapter() {
	}

	public ImitateUCMenuGridViewAdapter(Context context,
			ImitateUCMenuItemData ucMenuItemData) {
		this.context = context;
		this.ucMenuItemData = ucMenuItemData;
		inflater = LayoutInflater.from(this.context);
	}

	public void refreshMenuItemData(ImitateUCMenuItemData ucMenuItemData) {
		this.ucMenuItemData = ucMenuItemData;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return ucMenuItemData.getMenuCount();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (null == view) {
			view = inflater.inflate(R.layout.imitate_uc_menu_main_menu_item,
					null);
		}
		
		ImageView imitateUCMenuMainMenuItemIV = (ImageView) view
				.findViewById(R.id.imitateUCMenuMainMenuItem_IV);
		imitateUCMenuMainMenuItemIV.setBackgroundDrawable(ucMenuItemData
				.getMenuDrawable(position));

		TextView imitateUCMenuMainMenuItemTV = (TextView) view
				.findViewById(R.id.imitateUCMenuMainMenuItem_TV);
		imitateUCMenuMainMenuItemTV.setText(ucMenuItemData
				.getMenuTitle(position));
		return view;
	}
}
